import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { OrderInfoEntity } from '../../entity/info';
import { OrderPayService } from "../../service/pay";

/**
 * order模块-订单信息
 */
@CoolController({
  prefix: "/apid",
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderInfoEntity,
  service: OrderPayService,
  pageQueryOp: {
    keyWordLikeFields: ['orderNumber', 'user', 'product'],
    fieldEq: ['status', 'paymentMethod'],
  }
})
export class AdminOrderInfoController extends BaseController {
  @Inject()
  orderPayService: OrderPayService;

  @Post("/aliApp", { summary: "支付宝APP支付" })
  async aliApp(
    @Body("goodsId") goodsId: number,
    @Body("orderType") orderType: number,
    @Body("orderPayType") orderPayType:number
  ) {
    return this.ok(await this.orderPayService.aliApp(goodsId, orderType,orderPayType));
  }

  @Get("/goodsInfo", { summary: "获取订单资源" })
  async goodsInfo(@Query("goodsId") goodsId: number) {
    return this.ok(await this.orderPayService.goodsInfo(goodsId));
  }

  @Post("/orderResult", { summary: "获取订单资源" })
  async orderResult(@Body() BodyData: any) {
    console.log(BodyData, 'query1121')
    return this.ok(await this.orderPayService.orderResult(BodyData));
  }

  @Get("/getOrderState", { summary: "获取订单状态" })
  async getOrderState(@Query() queryData: any) {
    return this.ok(await this.orderPayService.getOrderState(queryData));
  }

  @Get("/getClientAnchorList", { summary: "获取相册资源" })
  async getClientAnchorList(@Query() queryData: any) {
    return this.ok(await this.orderPayService.getClientAnchorList(queryData));
  }

  // 获取主播相册
  @Get("/getClientAnchorAlbumList", { summary: "获取主播相册" })
  async getClientAnchorAlbumList(@Query() queryData: any) {
    return this.ok(await this.orderPayService.getClientAnchorAlbumList(queryData));
  }

  // 获取视频秘钥
  @Get("/getGenSig", { summary: "生成秘钥" })
  async getGenSig(@Query() queryData: any) {
    return this.ok(await this.orderPayService.getGenSig(queryData));
  }

  // 微信支付 
  // -- 微信token
  @Get("/checkSignature", { summary: "生成秘钥" })
  async checkSignature(@Query() queryData: any) {
    let res = await this.orderPayService.checkSignature(queryData)
    return res;
  }

  // -- 微信token
  @Get("/getWxOpenId", { summary: "生成秘钥" })
  async getWxOpenId(@Query() queryData: any) {
    let res = await this.orderPayService.getWxOpenId(queryData)
    return res;
  }

  @Post("/getPrepayInfo", { summary: "生成订单" })
  async getPrepayInfo(@Body() bodyData: any) {
    let res = await this.orderPayService.getPrepayInfo(bodyData)
    return res;
  }

  // 微信支付回调
  @Post("/wxOrderResult", { summary: "获取订单状态" })
  async wxOrderResult(@Body() BodyData: any) {
    console.log(BodyData, 'query1121')
    return this.ok(await this.orderPayService.wxOrderResult(BodyData));
  }

}
